#include <iostream>
using namespace std;

const int maxlen = 101;
char map[maxlen][maxlen];
int n, m;

void dfs(int x, int y)
{
	map[x][y] = '.';
	for (int dx = -1; dx <= 1; ++dx)
		for (int dy = -1; dy <= 1; ++dy) {
			int tx = x + dx, ty = y + dy;
			if (0 <= tx && tx < n && 0 <= ty && ty < m
					&& map[tx][ty] == 'W') {
				map[tx][ty] = '.';
				dfs(tx, ty);
			}
		}
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j) cin >> map[i][j];
	int tot = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			if (map[i][j] == 'W') {
				++tot;
				dfs(i, j);
			}
	cout << tot << endl;
	return 0;
}
